package tmt.usercenter.web.domain;


import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.tmt.annotation.LazyLoadDefine;
import com.tmt.annotation.LazyLoadMapping;
import com.tmt.annotation.Select2OptionValue;
import com.tmt.jpafieldvalueconvert.JpaFieldValueConvert;
import com.tmt.jpafieldvalueconvert.JpaFieldValueConvertListener;
import com.tmt.jpafieldvalueconvert.impl.FileUrlFieldConverter;
import com.voodoodyne.jackson.jsog.JSOGGenerator;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import tmt.usercenter.web.domain.enums.IdCardType;
import tmt.usercenter.web.domain.security.BaseAuditor;

import javax.persistence.*;
import java.io.Serializable;

@Getter
@Setter
@Entity
@JsonIgnoreProperties(value={"hibernateLazyInitializer","handler","fieldHandler"})
@EntityListeners({JpaFieldValueConvertListener.class, AuditingEntityListener.class})
@JsonIdentityInfo(generator = JSOGGenerator.class)
@LazyLoadDefine({
		@LazyLoadMapping(name = "1", value = {"user"})
})
public class RealNameMaterial extends BaseAuditor implements Serializable {

	/**
	 * 身份证持有人
	 */
	@Column(nullable = false)
	private String name;

	/**
	 * 证件号码
	 */
	@Column(nullable = false)
	private String cardNo;

	/**
	 * 证件类型
	 */
	@Select2OptionValue("cardType")
	@Enumerated(EnumType.STRING)
	@Column(nullable = false)
	private IdCardType cardType = IdCardType.ID_CARD_2;

	/**
	 * 证件正面
	 */
	@Column(nullable = false)
	@JpaFieldValueConvert(converter = FileUrlFieldConverter.class, displayName = "证件正面照片")
	private String front = "";

	/**
	 * 证件背面
	 */
	@Column(nullable = false)
	@JpaFieldValueConvert(converter = FileUrlFieldConverter.class, displayName = "证件背面照片")
	private String back = "";

	/**
	 * 所属用户
	 */
	@ManyToOne(cascade = {CascadeType.REFRESH}, fetch = FetchType.LAZY, optional = false)
	@JoinColumn(name = "user_id", nullable = false)
	private TmtUser user;

}
